package org.example;

import org.openjdk.jol.info.ClassLayout;

import java.util.concurrent.TimeUnit;

public class Main2 {

    public static void main(String[] args) throws InterruptedException {
        Object o = new Object();
        Thread thread = new Thread(() -> synchronizedMethod(o));
        Thread thread2 = new Thread(() -> synchronizedMethod(o));
        thread.start();
        TimeUnit.SECONDS.sleep(5);
        while (thread.isAlive()) {

        }
        System.out.println(thread.isAlive());
        thread2.start();
        TimeUnit.SECONDS.sleep(10);
    }

    static void synchronizedMethod(Object o) {
        System.out.println(ClassLayout.parseInstance(o).toPrintable());
        synchronized (o) {
            System.out.println(ClassLayout.parseInstance(o).toPrintable());
        }
        System.out.println(ClassLayout.parseInstance(o).toPrintable());
        System.out.println("=============" + Thread.currentThread().getId() + "=============");
    }
}
